<template>
  <div id="employee">
    <div class="table">
      <Table stripe
             :columns="columns"
             class="table-list"
             :data="data"></Table>
      <div class="page-box">
        <Page :total="total"
              :page-size='pageSize'
              show-total
              show-sizer
              @on-change='changePageIndex'
              @on-page-size-change='changePageSize' />
      </div>
    </div>
  </div>
</template>

<script>
import { getUserList } from '@/api/system/org'
export default {
  name: 'role_employee',
  data () {
    return {
      total: 0,
      pageIndex: 1,
      pageSize: 10,
      columns: [
        {
          title: ' ',
          width: 70
        },
        {
          title: '姓名',
          key: 'username'
        },
        {
          title: '手机号',
          key: 'phoneNumber'
        },
        {
          title: '邮箱',
          key: 'email'
        },
        {
          title: '组织',
          key: 'orgName'
        }
      ],
      data: []
    }
  },
  methods: {
    changePageIndex (page) {
      this.pageIndex = page
      this.getData()
    },
    changePageSize (size) {
      this.pageSize = size
      this.getData()
    },
    getData () {
      getUserList({ 'merchantId': this.$store.state.user.merchantId, roleId: this.$route.params.id, pageIndex: this.pageIndex, pageSize: this.pageSize, status: 1 }).then(res => {
        if (res.data.status === 200) {
          this.data = res.data.data.records
          this.total = res.data.data.total
          // if (res.data.data.records.length / this.pageSize === 0) {
          //   if (this.pageIndex > 1) {
          //     this.pageIndex--
          //     this.getData()
          //   }
          // }
        } else {
          this.$Message.error(`${res.data.error}`)
        }
      })
    }
  },
  mounted () {
    this.getData()
  }
}
</script>

<style lang='less' scoped>
.table-list{
  border-top:none;
}
</style>
